package st.business.tepth.business.user.busnumber.workholder.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;

import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.base.OnItemChooseListener;
import st.business.tepth.business.bean.PickGoods;

/**
 * @author zhangyu
 * @date 2019/2/22
 */
public class DialogConfirmProgram extends Dialog {
    public DialogConfirmProgram(Context context,
                                final List<PickGoods> multipleItemEntities,
                                final OnItemChooseListener<String> listener) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = LayoutInflater.from(context).
                inflate(R.layout.dialog_confirm_program, null);
        view.findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(new BaseQuickAdapter<PickGoods, BaseViewHolder>
                (R.layout.item_goods_delete, multipleItemEntities) {
            @Override
            protected void convert(BaseViewHolder helper, PickGoods item) {
                helper.setText(R.id.tv_part_name, item.getMaterialName());
                helper.setText(R.id.tv_brand, "品牌:" + item.getBrand());
                helper.setText(R.id.tv_version, "型号:" + item.getModelNo());
                helper.setText(R.id.tv_specification, "规格:" + item.getSpecifications());
                helper.setText(R.id.tv_batch, "批次:" + item.getBatchNo());
                helper.setText(R.id.tv_check_state, item.getValue() + item.getUnit());
            }
        });
        view.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onChoose(JSON.toJSONString(multipleItemEntities));
                }
                dismiss();
            }
        });
        setContentView(view);
    }

}
